package com.neusoft.yiyang.medical.controller;

import com.neusoft.yiyang.medical.assistant.YiYangAgent;
import com.neusoft.yiyang.medical.bean.ChatForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@Tag(name = "东软小智接口", description = "提供医疗相关的智能对话服务，支持实时交互与响应")
@RestController
@RequestMapping("/yiyang")
public class YiYangController {
    @Autowired
    private YiYangAgent yiYangAgent;

    @Operation(summary = "智能对话交互", description = "与东软小智进行医疗相关对话，支持上下文记忆（通过memoryId关联对话历史）")
    @PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ServerSentEvent<String>> chat(
            @Parameter(description = "对话表单（含memoryId和消息内容）", required = true)
            @RequestBody ChatForm form) {
        return yiYangAgent.chat(form.getMemoryId(), form.getMessage())
                .map(data -> ServerSentEvent.builder(data).build());
    }

}